package com.ewzj.bigdata.mvp.ui.adapter

import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ewzj.bigdata.R
import com.ewzj.bigdata.mvp.model.rspbean.SubFilterBean
import com.jess.arms.utils.UiUtils
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration

import java.util.ArrayList

import io.reactivex.Observable
import io.reactivex.functions.Consumer

/**
 * author:zhangjing
 * 作用:
 * return:
 */

class MoretagAdapter(data: List<SubFilterBean.DataEntity>) : BaseQuickAdapter<SubFilterBean.DataEntity, BaseViewHolder>(R.layout.popwindow_more_item, data) {
    private val moreItemTagAdapters: List<MoreItemTagAdapter>

    val selecteditems: List<SubFilterBean.DataEntity.ChildrenEntity>
        get() {
            val list = ArrayList<SubFilterBean.DataEntity.ChildrenEntity>()
            Observable.fromIterable(mData).map { t -> t.children }.flatMap { t->Observable.fromIterable(t) }
                    .filter { t: SubFilterBean.DataEntity.ChildrenEntity ->  t.isseld()}
                    .subscribe(Consumer { t ->list.add(t)  })
            return list
        }
    init {
        moreItemTagAdapters = ArrayList<MoreItemTagAdapter>()
    }

    override fun convert(baseViewHolder: BaseViewHolder, dataEntity: SubFilterBean.DataEntity) {
        baseViewHolder.setText(R.id.tv_tag, dataEntity.name)
        val recyclerView = baseViewHolder.getView<RecyclerView>(R.id.rv_tag)
        if (recyclerView.adapter == null) {
            recyclerView.layoutManager = GridLayoutManager(mContext, 3)
            recyclerView.addItemDecoration(HorizontalDividerItemDecoration.Builder(mContext)
                    .colorResId(R.color.white).size(UiUtils.dip2px(mContext, 20f)).build(), 0)
        } else {

        }
        val moreItemTagAdapter = MoreItemTagAdapter(dataEntity.children)
        //        moreItemTagAdapters.add(moreItemTagAdapter);
        recyclerView.adapter = moreItemTagAdapter
    }
}
